package gr.anagnosg.general.utils;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DateUtils {
    public DateUtils() {
        super();
    }
    public static String  getCurrentDate(){    
        
        Date dt = new Date();
        SimpleDateFormat sf = new SimpleDateFormat("dd/MM/yyyy");
        String currDate = sf.format(dt);
        return currDate;
    }
    public static java.sql.Date  str2SqlDate(String dateStr){    
        SimpleDateFormat sf = new SimpleDateFormat("dd/MM/yyyy");
        Date dateT = sf.parse(dateStr, new ParsePosition(0));
        java.sql.Date dateSqlT = new java.sql.Date(dateT.getTime());
        return dateSqlT;
    }
    
    public static String  date2Str(java.sql.Date d){    
        SimpleDateFormat sf = null;
        String date = null;
        if(d!=null){
            sf = new SimpleDateFormat("dd/MM/yyyy");
            date = sf.format(new Date(d.getTime()));
        }
        else{
            date="";    
        }
        return date;
    }
    
    public static String getCurrentTimeStr(){
        String output="";
        Date d = new Date();
        SimpleDateFormat sd = new SimpleDateFormat("yyyyMMddHHmmss");
        //dd/MM/yyyy HH:mm:ss");
        //             output =sdf.format(new Date(input)); 
        output = sd.format(d);
        return output;
    }
    
    public static String getDateTimeStr(Date d){
        String output="";
        //Date d = new Date();
        SimpleDateFormat sd = new SimpleDateFormat("yyyyMMddHHmmss");
        //dd/MM/yyyy HH:mm:ss");
        //             output =sdf.format(new Date(input)); 
        output = sd.format(d);
        return output;
    }
    
    public static String getDateTimeStr(Date d,String format){
        String output="";
        //Date d = new Date();
        SimpleDateFormat sd = new SimpleDateFormat(format);
        //dd/MM/yyyy HH:mm:ss");
        //             output =sdf.format(new Date(input)); 
        output = sd.format(d);
        return output;
    }
    
    public static String formatDate(long time){
        String output="";
        
        SimpleDateFormat sd = new SimpleDateFormat("dd/MM/yyyy  HH:mm:ss");
        
        
        output = sd.format(time);
        return output;
        
    }
    
    public static Date addDays(int days){ 
        Calendar c=new GregorianCalendar();
        c.add(Calendar.DATE, days);
        Date d=c.getTime();
        return d;
    }
}
